home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / apps / 102 / examples / recursep.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-01-25  |  1.3 KB  |  43 lines

  1. /*
  2.  * run this with 'test1' as the first command line argument.  It will
  3.  * recurse to three levels if the 'test1, 'test2' and 'test3' files are
  4.  * available for it to read.  This program works fine with Lattice C
  5.  * but fails miserably with the orignial developers kit.
  6.  * Works ok in Mark Williams C - CJPurcell - 16Jan'87 - added Bconin/pause.
  7.  */
  8.  
  9. #include "stdio.h"
  10. #include <osbind.h>
  11.  
  12. int     main(argc,argv) int     argc;
  13.                         char    **argv;
  14. {
  15.         FILE    *in;
  16.         if (argc > 1)
  17.         {
  18.                 if ((in = fopen(argv[1],"r")) == NULL) exit(1);
  19.                 echofile(in);
  20.                 fclose(in);
  21.         }
  22.         Cconws("This is recursive demonstration. Press any key to return\r\n");
  23.         Bconin(2);
  24.         exit(0);
  25. }
  26. int     echofile(in)  FILE    *in;
  27. {
  28.         FILE    *newin;
  29.         char    line[BUFSIZ];
  30.         while (fgets(line,BUFSIZ,in))
  31.         {
  32.                 printf("%s",line);
  33.                 if (! strncmp(line,"read ",5))
  34.                 {
  35.                         line[strlen(line)-1] = 0;
  36.                         if ((newin = fopen(line+5,"r")) == NULL) continue;
  37.                         echofile(newin);
  38.                         fclose(newin);
  39.                 }
  40.         }
  41.         return 0;               
  42. }
  43.